package biz.obake.team.touchprotector.lfd;

import android.content.DialogInterface;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.EditText;
import android.widget.GridView;
import androidx.appcompat.app.b;
import biz.obake.team.touchprotector.R;
import biz.obake.team.touchprotector.g.c;
import biz.obake.team.touchprotector.tpservice.TPService;

public class LfdCustomActivity extends androidx.appcompat.app.c implements c.b {
    private GridView t;
    /* access modifiers changed from: private */
    public g u;
    private boolean v = false;

    class a implements DialogInterface.OnClickListener {
        a(LfdCustomActivity lfdCustomActivity) {
        }

        public void onClick(DialogInterface dialogInterface, int i) {
        }
    }

    class b implements DialogInterface.OnClickListener {
        b() {
        }

        public void onClick(DialogInterface dialogInterface, int i) {
            LfdCustomActivity.this.startActivity(new Intent("android.intent.action.VIEW", Uri.parse("market://details?id=com.google.android.apps.photos")));
        }
    }

    class c implements AdapterView.OnItemClickListener {
        c() {
        }

        public void onItemClick(AdapterView<?> adapterView, View view, int i, long j) {
            LfdCustomActivity.this.N(i);
        }
    }

    class d implements AdapterView.OnItemLongClickListener {
        d() {
        }

        public boolean onItemLongClick(AdapterView<?> adapterView, View view, int i, long j) {
            LfdCustomActivity.this.O(i);
            return true;
        }
    }

    class e implements View.OnClickListener {
        e() {
        }

        public void onClick(View view) {
            LfdCustomActivity.this.M();
        }
    }

    class f implements View.OnClickListener {
        f() {
        }

        public void onClick(View view) {
            LfdCustomActivity.this.P();
        }
    }

    class g implements DialogInterface.OnClickListener {

        /* renamed from: b  reason: collision with root package name */
        final /* synthetic */ EditText f1721b;

        /* renamed from: c  reason: collision with root package name */
        final /* synthetic */ int f1722c;

        g(EditText editText, int i) {
            this.f1721b = editText;
            this.f1722c = i;
        }

        public void onClick(DialogInterface dialogInterface, int i) {
            b.i().m(this.f1722c, this.f1721b.getText().toString());
            LfdCustomActivity.this.u.notifyDataSetChanged();
        }
    }

    class h implements DialogInterface.OnClickListener {

        /* renamed from: b  reason: collision with root package name */
        final /* synthetic */ int f1724b;

        h(int i) {
            this.f1724b = i;
        }

        public void onClick(DialogInterface dialogInterface, int i) {
            b.i().f(this.f1724b);
            LfdCustomActivity.this.u.notifyDataSetChanged();
        }
    }

    class i implements DialogInterface.OnClickListener {
        i(LfdCustomActivity lfdCustomActivity) {
        }

        public void onClick(DialogInterface dialogInterface, int i) {
        }
    }

    private void L() {
        Uri uri;
        Intent intent = getIntent();
        if ("android.intent.action.SEND".equals(intent.getAction()) && intent.getType() != null && (uri = (Uri) intent.getParcelableExtra("android.intent.extra.STREAM")) != null) {
            try {
                b.i().d(uri);
                this.v = true;
            } catch (Exception unused) {
            }
        }
    }

    /* access modifiers changed from: private */
    public void M() {
        Intent intent = new Intent();
        intent.setAction("android.intent.action.PICK");
        intent.setType("image/*");
        startActivityForResult(intent, 0);
    }

    /* access modifiers changed from: private */
    public void N(int i2) {
        f.d().i(b.i().a(i2));
        this.u.notifyDataSetChanged();
        TPService.k("Design", "LfdCustom");
    }

    /* access modifiers changed from: private */
    public void O(int i2) {
        View inflate = getLayoutInflater().inflate(R.layout.lfd_dialog, (ViewGroup) null);
        EditText editText = (EditText) inflate.findViewById(R.id.editText);
        editText.setText(b.i().c(i2));
        b.a aVar = new b.a(this, 2131689481);
        aVar.s(R.string.lfd_custom_dialog_title);
        aVar.u(inflate);
        aVar.j(R.string.lfd_cumstom_dialog_cancel, new i(this));
        aVar.l(R.string.lfd_cumstom_dialog_delete, new h(i2));
        aVar.o(R.string.lfd_cumstom_dialog_set, new g(editText, i2));
        aVar.a().show();
    }

    /* access modifiers changed from: private */
    public void P() {
        String w = biz.obake.team.touchprotector.c.w(R.string.lfd_custom_activity_web_uri);
        if (w != null && w.length() != 0) {
            startActivity(new Intent("android.intent.action.VIEW", Uri.parse(w)));
        }
    }

    private void Q(Exception exc) {
        String replace = biz.obake.team.touchprotector.c.w(R.string.lfd_custom_err_dialog_message).replace("{0}", exc.getMessage());
        b.a aVar = new b.a(this);
        aVar.s(R.string.lfd_custom_err_dialog_title);
        aVar.h(replace);
        aVar.o(R.string.lfd_custom_err_dialog_yes, new b());
        aVar.j(R.string.lfd_custom_err_dialog_no, new a(this));
        aVar.a().show();
    }

    private void R() {
        int i2;
        GridView gridView;
        if ("Locked".equals(biz.obake.team.touchprotector.g.c.c("TPService.State"))) {
            gridView = this.t;
            i2 = 4;
        } else {
            gridView = this.t;
            i2 = 0;
        }
        gridView.setVisibility(i2);
    }

    /* access modifiers changed from: protected */
    public void onActivityResult(int i2, int i3, Intent intent) {
        if (-1 == i3) {
            try {
                b.i().d(intent.getData());
                this.t.invalidateViews();
            } catch (Exception e2) {
                Q(e2);
            }
        }
    }

    /* access modifiers changed from: protected */
    public void onCreate(Bundle bundle) {
        super.onCreate(bundle);
        setContentView((int) R.layout.lfd_custom_activity);
        this.t = (GridView) findViewById(R.id.gridView);
        g gVar = new g(b.i());
        this.u = gVar;
        this.t.setAdapter(gVar);
        this.t.setOnItemClickListener(new c());
        this.t.setOnItemLongClickListener(new d());
        ((Button) findViewById(R.id.add)).setOnClickListener(new e());
        Button button = (Button) findViewById(R.id.web);
        if (button != null) {
            button.setOnClickListener(new f());
        }
        if (bundle != null) {
            this.v = bundle.getBoolean("CustomDesignSharingHandled", false);
        }
        if (!this.v) {
            L();
        }
    }

    /* access modifiers changed from: protected */
    public void onPause() {
        super.onPause();
        biz.obake.team.touchprotector.g.c.h(this);
    }

    public void onRamPrefsChanged(String str) {
        if (((str.hashCode() == -2066548004 && str.equals("TPService.State")) ? (char) 0 : 65535) == 0) {
            R();
        }
    }

    /* access modifiers changed from: protected */
    public void onResume() {
        super.onResume();
        R();
        biz.obake.team.touchprotector.g.c.e(this);
    }

    /* access modifiers changed from: protected */
    public void onSaveInstanceState(Bundle bundle) {
        super.onSaveInstanceState(bundle);
        if (isChangingConfigurations()) {
            bundle.putBoolean("CustomDesignSharingHandled", this.v);
        }
    }
}
